import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:speed_random/app_styles.dart';


// 底部状态按钮
class rowRunOrSetButtons extends StatelessWidget {
  final int isRun;
  final bool isManualStop;
  final VoidCallback onGetRandomNumPressed;
  final VoidCallback onStopPressed;
  final VoidCallback onOkPressed;
  final VoidCallback onSettingsPressed;
  final String getRandomNumText;
  final String settingsText;

  const rowRunOrSetButtons({
    Key? key,
    this.isRun=0,
    this.isManualStop=false,
    required  this.onGetRandomNumPressed,
    required this.onSettingsPressed,
    required  this.onStopPressed,
    required  this.onOkPressed,
    this.getRandomNumText = '开始',
    this.settingsText = '设置',
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {

    return [rowTwoButtons(
      getRandomNumText: getRandomNumText,
      settingsText: settingsText,
      onGetRandomNumPressed: ()async{
        onGetRandomNumPressed();
      },
      onSettingsPressed: ()async{
        onSettingsPressed();
      },
    ),ElevatedButton(
      style: ElevatedButton.styleFrom(
        backgroundColor:isManualStop?Color(0xffff6f3c):Color(0xffe7e6e1),
      ),
      onPressed: (){
        if(isManualStop){
          onStopPressed() ;
        }
      },
      child: Text(isManualStop?"停止".tr:("进行中".tr+"……"), style: TextStyle(color: Colors.white)),
    ),ElevatedButton(
      style: ElevatedButton.styleFrom(
        backgroundColor: AppStyles.colorOkButbg,
      ),
      onPressed: onOkPressed,
      child: Text("完成".tr, style: TextStyle(color: Colors.white)),
    )][isRun>2?0:isRun];
  }
}


// 封装的新组件
class rowTwoButtons extends StatelessWidget {
  final VoidCallback onGetRandomNumPressed;
  final VoidCallback onSettingsPressed;
  final String getRandomNumText;
  final String settingsText;

  const rowTwoButtons({
    Key? key,
    required this.onGetRandomNumPressed,
    required this.onSettingsPressed,
    this.getRandomNumText = '获取随机数',
    this.settingsText = '设置',
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        Expanded(
          child: ElevatedButton(
            style: ElevatedButton.styleFrom(
              backgroundColor: AppStyles.colorPageText,
            ),
            onPressed: onGetRandomNumPressed,
            child: Text(getRandomNumText.tr, style: TextStyle(color: Colors.white)),
          ),
        ),
        const SizedBox(width: 16),
        ElevatedButton(
          style: ElevatedButton.styleFrom(
            backgroundColor: AppStyles.colorPageText,
          ),
          onPressed: onSettingsPressed,
          child: Row(
            children: [
              Icon(Icons.settings, color: Colors.white),
              Text(settingsText.tr, style: TextStyle(color: Colors.white))
            ],
          ),
        ),
      ],
    );
  }
}